package com.qyl.sever_rpc.util;

import com.baidu.bjf.remoting.protobuf.Codec;
import com.baidu.bjf.remoting.protobuf.ProtobufProxy;
import com.qyl.sever_rpc.pojo.Args2;

import java.nio.charset.StandardCharsets;

public class SerializeUtil2 {
    // 序列化
    public static String serializeArgs(Args2 args) throws Exception{
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(args);
//        byte[] bytes = json.getBytes();
        //
        //Protobuf
        //
        Codec<Args2> poCodec = ProtobufProxy.create(Args2.class);
//        System.out.println("res:  "+objectMapper.writeValueAsString(poCodec.decode(poCodec.encode(args))));
        return new String(poCodec.encode(args));
//            //

    }

    // 反序列化
    public static Args2 getSerializeArgs(String str) throws Exception{
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(args);
//        byte[] bytes = json.getBytes();
        //
        //Protobuf
        //
        Codec<Args2> poCodec = ProtobufProxy.create(Args2.class);
//        System.out.println("res:  "+objectMapper.writeValueAsString(poCodec.decode(poCodec.encode(args))));
        return poCodec.decode(str.getBytes(StandardCharsets.UTF_8));
//            //

    }

}
